package com.shhm.business.controller.seller;

import com.shhm.business.service.ProductService;
import com.shhm.common.annotations.OperateLog;
import com.shhm.common.dto.request.RequestList;
import com.shhm.common.dto.response.AjaxResultPlus;
import com.shhm.common.dto.response.business.ProductVO;
import com.shhm.common.entity.common.ProductEntity;
import com.shhm.common.utils.JwtUtil;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

/**
 * @author JackZ
 * @version 1.0
 * @description: TODO
 * @date 2025/9/2 下午9:16
 */
@RestController
@RequestMapping("/seller")
public class SellerProductController {
    @Resource
    private ProductService productService;

    @PostMapping("/product")
    @OperateLog(module="商品管理",type = "POST",desc = "添加商品信息")
    public AjaxResultPlus add(@RequestBody ProductEntity entity, HttpServletRequest request){
        return productService.add(entity,request);
    }


    @GetMapping("/product")
    public AjaxResultPlus sellerProductList(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "1") Integer isPage,
            HttpServletRequest request
    ){
        return productService.sellerProductList(pageNum,pageSize,isPage,request);
    }

    @PostMapping("/product/search")
    public AjaxResultPlus pageSearchList(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestBody ProductVO entity,
            HttpServletRequest request
    ){
        Long uid = JwtUtil.getUIDFromAuth(request);
        entity.setSellerId(uid);
        return productService.pageSearchList(pageNum,pageSize,entity,request);
    }

    @PutMapping("/product")
    @OperateLog(module="商品管理",type = "PUT",desc = "修改商品信息")
    public AjaxResultPlus update(@RequestBody ProductVO entity, HttpServletRequest request){
//        System.out.println("entity = " + entity);
        return productService.update(entity,request);
    }

    @DeleteMapping("/product")
    @OperateLog(module="商品管理",type = "DELETE",desc = "删除商品")
    public AjaxResultPlus delete(@RequestBody RequestList ids, HttpServletRequest request){
        return productService.delete(ids,request);
    }
}
